package frame;

import data.DataInXlsx;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static data.DataInXlsx.DataInXlsxfun;

public class MainFrame extends JFrame {
    static JPanel panelTable;
    public static void initpanelTable(){
        if(panelTable != null)panelTable.removeAll();
//        panelTable = new JPanel();
        panelTable.setBounds(0,40,1900,950);
        panelTable.setBackground(new Color(0x33000019, true));
        panelTable.setLayout(null);
        ShowTableFrame showTableFrame=new ShowTableFrame();
        panelTable.add(showTableFrame.scrollPane);
        panelTable.updateUI();
    }
    public MainFrame(){
        super("大乐透");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);
        // 设置窗口的大小
        this.setSize(1920, 1040);

        // 创建一个面板来放置按钮
        JPanel panelFun = new JPanel();
        panelFun.setBounds(0,0,1920,40);
        panelFun.setBackground(new Color(0x79FFF2C5, true));

        // 创建并添加5个按钮
        JButton button1add = new JButton("添加");
        button1add.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 取消按钮的逻辑（例如关闭窗口）
                new addOnelottoframe();
//                initpanelTable();
//                dispose();
            }
        });
        JButton button2Find = new JButton("查找");
        button2Find.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        new findlottoFrame();
                    }
                });
            }
        });

        JButton button3 = new JButton("数据导入");
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 取消按钮的逻辑（例如关闭窗口）
                DataInXlsxfun();
//                initpanelTable();
//                dispose();
            }
        });
        JButton button4 = new JButton("历史数据分析");
        button4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 取消按钮的逻辑（例如关闭窗口）
                new lishiDatafenxiFrame();
//                initpanelTable();
//                dispose();
            }
        });
        JButton button5 = new JButton("随机一注");
        button5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 取消按钮的逻辑（例如关闭窗口）
                new chessoOneFrame();
//                new lishiDatafenxiFrame();
//                initpanelTable();
//                dispose();
            }
        });

        // 将按钮添加到面板中
        panelFun.add(button1add);
        panelFun.add(button2Find);
        panelFun.add(button3);
        panelFun.add(button4);
        panelFun.add(button5);

        panelTable = new JPanel();
        initpanelTable();

        // 将面板添加到窗口中
        this.getContentPane().add(panelFun);
        this.getContentPane().add(panelTable);
        // 设置窗口可见
        this.setVisible(true);
        new Thread(new MainFrame.NoWeightedGoods()).start();
    }
    public static void main(String[] args){
        new MainFrame();
    }
    public class NoWeightedGoods implements Runnable{
        @Override
        public void run() {
            while(true){
                repaint();
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}
